/**
 * 
 */
package com.rd.sys.service.sys.user.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import baseproj.component.log.LoggerAdapter;
import baseproj.component.log.LoggerService;

import com.rd.sys.common.base.CommonConstants;
import com.rd.sys.service.sys.user.UserSubscriptionService;

/**
 * @author
 * 
 */
@Service
@Transactional(rollbackFor = {Exception.class})
public class UserSubscriptionServiceImpl implements UserSubscriptionService {
    private final LoggerService logger = LoggerAdapter.getLoggerService(getClass());

    /**
     * 激活码编码
     * 
     * @param activationCode
     * @return
     */
    @Transactional(readOnly = true)
    public String enActivationCode(String activationCode) {
        StringBuffer sb = new StringBuffer();
        activationCode = activationCode.substring(0, CommonConstants.UserConstats.CLIENT_ACTIVATE_TOTAL_LENGTH);
        int index = 0;
        while (index < activationCode.length()) {
            sb.append(activationCode.substring(index, index + CommonConstants.UserConstats.CLIENT_ACTIVATE_PER_NUMBER)
                    + CommonConstants.UserConstats.CLIENT_ACTIVATE_SPLIT_SIGN);
            index += CommonConstants.UserConstats.CLIENT_ACTIVATE_PER_NUMBER;
        }
        return sb.substring(0, sb.length() - 1);
    }

    /**
     * 激活码解码
     * 
     * @param activationCode
     * @return
     */
    @Transactional(readOnly = true)
    public String deActivationCode(String activationCode) {
        return activationCode.replaceAll(CommonConstants.UserConstats.CLIENT_ACTIVATE_SPLIT_SIGN, "");
    }
}
